<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller 
{
	public function __construct()
	{
		// 先调用父类的构造函数
		parent::__construct();

		/* if((CONTROLLER_NAME == 'Appoint' && ACTION_NAME=='add') || (CONTROLLER_NAME == 'Consult' && ACTION_NAME=='add') || (CONTROLLER_NAME == 'Articles' && ACTION_NAME=='collect_add'))
			return TRUE; */

		$adminId = session('id');
		if(!$adminId)
			redirect(U('Admin/Login/login'));
		/* $url = MODULE_NAME .'/'. CONTROLLER_NAME . '/' . ACTION_NAME;
		$where = 'module_name="'.MODULE_NAME.'" AND controller_name="'.CONTROLLER_NAME.'" AND action_name="'.ACTION_NAME.'"';
		if(CONTROLLER_NAME == 'Index')
			return TRUE;
		
		if($adminId == 1) 
			$sql = 'SELECT COUNT(*) has FROM '.C('DB_PREFIX').'privilege WHERE '.$where;
		else  
			$sql = 'SELECT COUNT(a.role_id) has
			  FROM '.C('DB_PREFIX').'role_privilege a
			   LEFT JOIN '.C('DB_PREFIX').'privilege b ON a.pri_id=b.id
			   LEFT JOIN '.C('DB_PREFIX').'admin_role c ON a.role_id=c.role_id
			    WHERE c.admin_id='.$adminId.' AND '.$where;
		$db = M();
		$pri = $db->query($sql);
		if($pri[0]['has'] < 1)
			$this->error('无权访问！'); */
	}
	public function index()
	{
		$this->display();
	}
	public function menu()
	{
	/* 	$adminId = session('id');
		if($adminId == 1)
			$sql = 'SELECT * FROM '.C('DB_PREFIX').'privilege';
		else 
			$sql = 'SELECT b.*
			  FROM '.C('DB_PREFIX').'role_privilege a
			   LEFT JOIN '.C('DB_PREFIX').'privilege b ON a.pri_id=b.id
			   LEFT JOIN '.C('DB_PREFIX').'admin_role c ON a.role_id=c.role_id
			    WHERE c.admin_id='.$adminId;
		$db = M();
		$pri = $db->query($sql);
		$btn = array();  
		foreach ($pri as $k => $v)
		{
			// 找顶级权限
			if($v['parent_id'] == 0)
			{
				foreach ($pri as $k1 => $v1)
				{
					if($v1['parent_id'] == $v['id'])
					{
						$v['children'][] = $v1;
					}
				}
				$btn[] = $v;
			}
		}
		$this->assign('btn', $btn); */
		$this->display();
	}
	public function top()
	{
		$this->display();
	}
	public function main()
	{
		//系统信息
        /**
			 服务器操作系统: 	WINNT (127.0.0.1) 	Web 服务器: 	Apache/2.2.22
			 PHP 版本: 	5.4 	MySQL 版本: 	5.5.24
			 安全模式: 	否 	安全模式GID: 	否
			 Socket 支持: 	是 	时区设置: 	PRC
			 GD 版本: 	GD2 ( JPEG GIF PNG) 	Zlib 支持: 	是
			 版本: 	v1.0 	文件上传的最大大小:
		*/	 
	    $mysql_ver = mysql_get_server_info();       
	    $sys_info['os']            = PHP_OS;
	    $sys_info['ip']            = $_SERVER['SERVER_ADDR'];
	    $sys_info['web_server']    = $_SERVER['SERVER_SOFTWARE'];
	    $sys_info['php_ver']       = PHP_VERSION;
	    $sys_info['mysql_ver']     = $mysql_ver;
	    $sys_info['zlib']          = function_exists('gzclose') ?  '是':'否';
	    $sys_info['safe_mode']     = (boolean) ini_get('safe_mode') ?  '是':'否';
	    $sys_info['safe_mode_gid'] = (boolean) ini_get('safe_mode_gid') ?  '是':'否';
	    $sys_info['timezone']      = function_exists("date_default_timezone_get") ? date_default_timezone_get() : $_LANG['no_timezone'];
	    $sys_info['socket']        = function_exists('fsockopen') ?  '是':'否';
		$sys_info['gd'] = 'GD2( JPEG GIF PNG)';
	    $sys_info['max_filesize'] = ini_get('upload_max_filesize');

	    $data['sys_info']= $sys_info;
		$this->assign('data', $data)->display();
	}

	//生成首页 buildHtml
	public function makehtml_homepage(){
		// $contents = $this->fetch('Home@Index:index');
		// file_put_contents('d:/index.html', $contents);		
		$file_suffix = C('HTML_FILE_SUFFIX');
		$file_suffix = empty($file_suffix)? 'html':$file_suffix;
		$static_html_file = HTML_PATH.'index'.'.'.$file_suffix;
		if(file_exists($static_html_file)){
			@unlink($static_html_file);
		}		     
		$this->display('Index/index');
	}

	public function setPageBtn($title, $btnName, $btnLink)
	{
		$this->assign('_page_title', $title);
		$this->assign('_page_btn_name', $btnName);
		$this->assign('_page_btn_link', $btnLink);
	}
	
	/**
	 * ajax 修改指定表数据字段  一般修改状态 比如 是否推荐 是否开启 等 图标切换的
	 * table,id_name,id_value,field,value
	 */
	public function changeTableVal(){
	    $table = I('table'); // 表名
	    $id_name = I('id_name'); // 表主键id名
	    $id_value = I('id_value'); // 表主键id值
	    $field  = I('field'); // 修改哪个字段
	    $value  = I('value'); // 修改字段值
	    $id = M($table)->where("$id_name = $id_value")->save(array($field=>$value)); // 根据条件保存修改的数据
	}
}














